package com.gy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gy.entity.Form.FormEntity;
import com.gy.vo.form.MemberVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FormMapper extends BaseMapper<FormEntity> {
    @Insert("insert into result_form_user (form_id, user_id) values (#{id}, #{userId})")
    Boolean addMember(@Param("id") Long id, @Param("userId") Long userId);



    @Select("select user_id, form_role,createTime from result_form_user where form_id = #{id}")
    List<MemberVO> listMembers(@Param("id") Long id);


    @Delete("DELETE FROM result_form_user WHERE form_id = #{id} AND user_id = #{userId}")
    Boolean deleteMember(@Param("id") Long id, @Param("userId") Long userId);



    @Update("UPDATE result_form_user SET form_role = #{role} WHERE form_id = #{id} AND user_id = #{userId}")
    Boolean updateRole(Long id, Long userId, String role);


    IPage<FormEntity> selectFormsByUserIdPaged(Long userId, Page<FormEntity> formPage);

    @Insert("insert into result_form_user (form_id, user_id, form_role) values (#{formId}, #{userId}, 'admin')")
    void saveMember(@Param("formId") Long id, @Param("userId") Long userId);

}
